#include <amxmodx>
#include <items>
#include <fun>

new PLUGIN_NAME[] 	= "UM Item: Unlimited Ammo"
new PLUGIN_AUTHOR[] 	= "Cheap_Suit"
new PLUGIN_VERSION[] 	= "1.1"

new bool:g_UnlimitedAmmo[33] 
public plugin_init() 
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
	register_item("Unlimited Ammo", "No more reloads", 2000)
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
}

public client_connect(id) {
	g_UnlimitedAmmo[id] = false
}

public Enable_Item(id) {
	g_UnlimitedAmmo[id] = true
}

public Disable_Item(id) {
	g_UnlimitedAmmo[id] = false
} 

public Event_CurWeapon(id)
{
	if(!is_user_alive(id) || !is_user_connected(id)) {
		return PLUGIN_CONTINUE
	}
	
	if(!g_UnlimitedAmmo[id]) {
		return PLUGIN_CONTINUE
	}
		
	new Weapon_ID = read_data(2)
	new Clip = read_data(3)
		
	if(Weapon_ID == CSW_C4 
	|| Weapon_ID == CSW_KNIFE 
	|| Weapon_ID == CSW_HEGRENADE
	|| Weapon_ID == CSW_SMOKEGRENADE 
	|| Weapon_ID == CSW_FLASHBANG) {
		return PLUGIN_CONTINUE
	}

	new sWeaponName[32]
	get_weaponname(Weapon_ID, sWeaponName, 31)	
	if(Clip < 1)
	{	
		give_item(id, sWeaponName) 
      		engclient_cmd(id, sWeaponName) 
	}
	return PLUGIN_CONTINUE
}
